<%@ page language="java" import="java.awt.Font,java.awt.Color" pageEncoding="UTF-8"%>
<%@ page import="org.jfree.chart.ChartFactory,
                org.jfree.chart.JFreeChart,
                org.jfree.chart.plot.PlotOrientation,
                org.jfree.chart.servlet.ServletUtilities,
                org.jfree.data.category.CategoryDataset,
                org.jfree.chart.plot.CategoryPlot,
                org.jfree.data.general.DatasetUtilities,
                org.jfree.chart.axis.CategoryAxis,
                org.jfree.chart.axis.ValueAxis,
                org.jfree.chart.renderer.category.BarRenderer3D,
                org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
                org.jfree.chart.axis.AxisLocation,
                org.jfree.chart.renderer.category.CategoryItemRenderer,
                org.jfree.chart.ChartRenderingInfo,
                org.jfree.chart.entity.StandardEntityCollection"
                %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <%double[][] data = new double[][]{{672, 766, 223, 540, 126}, {325, 521, 210, 340, 106}, {332, 256, 523, 240, 526}};
  String[] rowsKeys={"苹果","梨子","葡萄"};
  String[] columnKeys={"北京","上海","广州","成都","深圳"};
  CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowsKeys,columnKeys,data);
  JFreeChart freechart = ChartFactory.createBarChart3D("水果销售量统计图","水果","销量",dataset,PlotOrientation.VERTICAL,true,true,true);
  freechart.setBackgroundPaint(Color.LIGHT_GRAY);
  freechart.getTitle().setPaint(Color.BLUE);
  //1
  CategoryPlot plot = freechart.getCategoryPlot();
  CategoryAxis domainAxis = plot.getDomainAxis();
  //设置距离图片左端距离
  domainAxis.setLowerMargin(0.02);
  //设置距离图片右端距离
  domainAxis.setUpperMargin(0.02);
  plot.setDomainAxis(domainAxis);
  
  //2
  ValueAxis rangeAxis = plot.getRangeAxis();
  //设置最高的一个柱与图片顶端的距离
  rangeAxis.setUpperMargin(0.08);
  //设置最低的一个柱与图片底端的距离
  rangeAxis.setLowerMargin(0.24);
  plot.setRangeAxis(rangeAxis);
  
  //3
  BarRenderer3D bar = new BarRenderer3D();
  bar.setBaseOutlinePaint(Color.BLACK);
  //设置 Wall 的颜色
  bar.setWallPaint(Color.darkGray);
  
  //设置每种水果代表的柱的颜色
  bar.setSeriesPaint(0,new Color(255,0,0));
  bar.setSeriesPaint(1,new Color(0,255,0));
  bar.setSeriesPaint(2,Color.BLUE);
  
  //设置每种水果代表的柱的 Outline 颜色
  bar.setSeriesOutlinePaint(0,Color.BLACK);
  bar.setSeriesOutlinePaint(1,Color.BLACK);
  bar.setSeriesOutlinePaint(2,Color.BLACK);
  //设置每个地区所包含的平行柱的之间距离
  bar.setItemMargin(0.02);
  //显示每个柱的数值，并修改该数值的字体属性
  bar.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
  bar.setDrawBarOutline(true);
  bar.setIncludeBaseInRange(true);
  bar.setItemLabelFont(new Font("华文新魏",Font.PLAIN,8));
  bar.setItemLabelsVisible(true);
  plot.setRenderer(bar);
  
  plot.setForegroundAlpha(1.00f);
  //设置地区、销量的显示位置
  //把生成的图片放到临时目录
 ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
  String filename=ServletUtilities.saveChartAsPNG(freechart,500,320,info,session);
  String grapUrl=request.getContextPath()+"/DisplayChart?filename=" + filename;%>
  
  <img src="<%=grapUrl%>" width="600" height="400" border="0" usemap="#<%=filename%>">
  <body> 
  </body>
</html>

